package com.atguigu.springboot_demo.controller;

import com.atguigu.springboot_demo.service.AdminService;
import com.atguigu.springboot_demo.entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class TestTemplateHandler {
    @Autowired
    private ServletContext servletContext ;

    @Autowired
    private AdminService adminService;

//    @RequestMapping("/test/thymeleaf")
    public String testThymeleaf(){
        return "hello" ;
    }

    @RequestMapping("/test/thymeleaf")
    public String testThymeleaf(ModelMap modelMap, HttpSession session){
        modelMap.addAttribute("attrNameRequestScope","<p style='color:blue;font-size:15px'>attrValueRequestScope</p>");
        session.setAttribute("attrNameSessionScope","attrValueSessionScope");
        servletContext.setAttribute("attrNameAppScope","attrValueAppScope") ;
        List<Admin> allAdmin = adminService.getAllAdmin();
        modelMap.addAttribute("adminList",allAdmin);
        return "hello" ;
    }
}
